package com.woniu.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.account.dto.venuePermission.VenuePermissionDto;
import com.woniu.account.model.VenuePermission;
import com.woniu.account.dao.VenuePermissionDao;
import com.woniu.account.service.VenuePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月11日
 */
@Service
public class VenuePermissionServiceImpl extends ServiceImpl<VenuePermissionDao, VenuePermission> implements VenuePermissionService {

    @Autowired
    private VenuePermissionDao venuePermissionDao;

    @Override
    public ArrayList<VenuePermissionDto> load(Integer venueAdminId) {
        ArrayList<VenuePermissionDto> venuePermissionDtos= venuePermissionDao.load(venueAdminId);
        ArrayList<VenuePermissionDto> level1 = new ArrayList<>();
        for (VenuePermissionDto venuePermissionDto : venuePermissionDtos) {
            if (venuePermissionDto.getLevel()==1) level1.add(venuePermissionDto);
        }
        for (VenuePermissionDto venuePermissionDto : venuePermissionDtos) {
            if (venuePermissionDto.getLevel()==2) {
                for (VenuePermissionDto venuePermissionDto1 : level1) {
                    if (venuePermissionDto1.getResourceId()==venuePermissionDto.getParentId()) venuePermissionDto1.getChildren().add(venuePermissionDto);
                }
            }
        }
        return level1;
    }
}
